package com.app.lxx.pregnancyberth.Mvp.Model;

import android.util.Log;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Lxx on 2018/9/13.
 */

public class CurrencyModel extends BaseModle {

    PostRequest<String> postRequest = null;
    GetRequest<String> getRequest = null;

    public void requestPostHttpModel(String url, StringCallback stringCallback) {
        postRequest = OkGo.post(url);
        postRequest.tag(this).execute(stringCallback);
        String cacheKey = postRequest.getCacheKey();
        Log.e("OkGo", "Url==>\n" + url);
        Log.e("OkGo", "Url==>\n" + cacheKey);
    }

    public void requestPostHttpModel(String url, HashMap<String, String> hashMap, StringCallback stringCallback) {
        postRequest = OkGo.post(url);
        postRequest.tag(this);
        List<String> keys = new ArrayList<>(hashMap.keySet());
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = hashMap.get(key);
            postRequest.params(key, value);
        }
        postRequest.execute(stringCallback);
        String cacheKey = postRequest.getCacheKey();
        Log.e("OkGo", "Url==>\n" + url);
        Log.e("OkGo", "Url==>\n" + cacheKey);
    }

    public void requestGetHttpModel(String url, StringCallback stringCallback) {
        getRequest = OkGo.<String>get(url);
        getRequest.tag(this).execute(stringCallback);
        String cacheKey = getRequest.getCacheKey();
        Log.e("OkGo", "Url==>\n" + url);
        Log.e("OkGo", "Url==>\n" + cacheKey);
    }

    public void requestGetHttpModel(String url, HashMap<String, String> hashMap, StringCallback stringCallback) {
        getRequest = OkGo.<String>get(url);
        getRequest.tag(this);
        List<String> keys = new ArrayList<>(hashMap.keySet());
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = hashMap.get(key);
            getRequest.params(key, value);
        }
        getRequest.execute(stringCallback);
        String cacheKey = getRequest.getCacheKey();
        Log.e("OkGo", "Url==>\n" + url);
        Log.e("OkGo", "Url==>\n" + cacheKey);
    }

}